<?php

class AccessControl {
	private static $_currentUser;

	/**
	 *
	 * @param boolean $reload
	 * @return User
	 */
	public static function getCurrentUser($reload = false) {
		if ($reload || self::$_currentUser == null) {
			self::$_currentUser = User::model()->findByPk(Yii::app()->user->id);
		}
		return self::$_currentUser;
	}

	public static function check($accessRule, $data = array()) {
		$user = self::getCurrentUser();
		if (($access = $user->userAccess) != null) {
			if (isset($access->$accessRule)) {
				return $access->$accessRule == 1;
			}
		}
		return false;
	}

	public static function checkEmployee() {
		$user = self::getCurrentUser();
		if ($user->employee != null && $user->employee->employed) {
			return true;
		}
		return false;
	}

	public static function isAltMode() {
		return false;
	}
}
